package org.ezplatform.office.meeting.notice.dao;

import java.util.List;

import org.ezplatform.core.dao.jpa.JpaBaseDao;
import org.ezplatform.office.meeting.notice.entity.NoticeInfo;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface NoticeInfoDao extends JpaBaseDao<NoticeInfo, String> {

    @Modifying
    @Query(value = "update NoticeInfo n set n.status=?2 where n.id =?1")
    void updateNoticeInfoStatus(String noticeInfoId, int status);

    @Modifying
    @Query(value = "delete from  NoticeInfo n where n.id in(?1)")
    void deleteList(List<String> list);
    
    @Modifying
    @Query(value = "delete from  NoticeInfo n where n.applyRecordId = ?1 and n.type='0'")
    void deleteApproveNotice(String applyRecordId);
    
    @Modifying
    @Query(value = "delete from NoticeInfo n where n.applyRecordId in (?1)")
    void deleteByApplyrecordId(String... id);

    @Modifying
    @Query(value = "delete from  NoticeInfo n where n.applyRecordId=?1 and n.type=?2")
    void deleteByApplyrecordId(String id,int type);

    @Modifying
    @Query(value = "update NoticeInfo n set n.isDelete=1 where n.id in(?1)")
    void updateNoticeInfoList(List<String> list);
    
    @Query(value = "select n.noticeUserId from NoticeInfo n where n.applyRecordId=?1 and n.status=4 and n.corpId=?2")
	List<String> getTurnoverUseIds(String applyRecordId, String corpId);
    
    @Query(value = "from NoticeInfo n where n.applyRecordId=?1 and n.noticeUserId=?2 and n.status=4")
	NoticeInfo findByTurnoverUserId(String applyRecordId, String turnoverUserId);
    
    @Query(value = "from NoticeInfo n where n.applyRecordId=?1 and n.noticeUserId=?2 and n.type=?3")
	NoticeInfo findByApplyrecordId(String applyRecordId, String noticeUserId, int type);
	
    @Query(value = "from NoticeInfo n where n.applyRecordId=?1 and n.noticeUserId=?2 and n.type=?3 and n.status!=4")
	NoticeInfo findAttendByApplyrecordId(String applyRecordId, String noticeUserId, int type);
    
    @Modifying
    @Query(value = "delete from NoticeInfo n where n.noticeUserId in (?1) and n.applyRecordId=?2 and n.corpId=?3")
    void deleteNoticeInfo(List<String> noticeUserIdList, String applyRecordId, String corpId);
    
    @Modifying
    @Query(value = "delete from NoticeInfo n where n.applyRecordId=?1 and n.corpId=?2")
    void deleteNoticeInfoByApplyrecordId(String applyRecordId, String corpId);
}